package com.xms.datacore;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

/**
 * <p>
 * DataCoreModuleInit
 * </p>
 *
 * @author migo
 * @since 2021/12/4
 */
@Component
public class DataCoreModuleInit implements ApplicationListener<ContextRefreshedEvent> {
    @Value("${spring.datasource.driver-class-name}")
    private String driverName;

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        if (driverName.indexOf("sqlserver") > 0) {
            DataBaseSetting.dataBaseType = DataBaseType.SQLSERVER;
        } else if (driverName.indexOf("oracle") > 0) {
            DataBaseSetting.dataBaseType = DataBaseType.ORACLE;
        } else if (driverName.indexOf("mysql") > 0) {
            DataBaseSetting.dataBaseType = DataBaseType.MYSQL;
        } else if (driverName.indexOf("postgresql") > 0) {
            DataBaseSetting.dataBaseType = DataBaseType.PGSQL;
        }
    }
}
